home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Graphics & Imaging / SLUDGE 2.0 / Source Code / Sludge.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-14  |  44.1 KB  |  1,067 lines  |  [TEXT/MPS ]

  1. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  2.   •                                                                           •
  3.   •   File Name:    SLUDGE.c                                                  •
  4.   •   ----------                                                              •
  5.   •                                                                           •
  6.   •   Copyright © 1990 Apple Computer, Inc.  All Rights Reserved              •
  7.   •                                                                           •
  8.   •       Description                                                         •
  9.   •       -----------                                                         •
  10.   •       This file contains most of the C language code for the SLUDGE cdev. •
  11.   •                                                                              •
  12.   •          The SLUDGE cdev slows down your mac.  It does so by making use of      •
  13.   •          the jump trace exception found in the 68020 and 68030 processors.      •
  14.   •          When SLUDGE is turned on, then at every jump trace exception it       •
  15.   •          executes a tight, inert, loop the number of times specified by the  •
  16.   •          SLUDGE factor.                                                      •
  17.   •                                                                              •
  18.   •                                                                           •
  19.   •       Author          Date            Description                         •
  20.   •       ------------------------------------------------------------------  •
  21.   •       Kevin McEntee   2/20/90         Original Implementation             •
  22.   •                                                                           •
  23.   •                                                                           •
  24.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  25.  
  26.                                          /*••••••••••••••••••••••••••••••••••••••••••
  27.                                            •                                        •
  28.                                            •    Include Files                        •
  29.                                            •                                        •
  30.                                            ••••••••••••••••••••••••••••••••••••••••••*/
  31. #include <Types.h>
  32. #include <Memory.h>
  33. #include <Quickdraw.h>
  34. #include <TextEdit.h>
  35. #include <Dialogs.h> 
  36. #include <Devices.h>
  37. #include <Scrap.h>
  38. #include <Lists.h>
  39. #include "State_Storage_Manager.h"
  40. #include    <ToolUtils.h>
  41. #include "Parasite_Manager.h"
  42.  
  43.                                          /*••••••••••••••••••••••••••••••••••••••••••
  44.                                            •                                        •
  45.                                            •    Constants that refer to the         •
  46.                                            •    controls of the SLUDGE cdev.        •
  47.                                            •                                        •
  48.                                            ••••••••••••••••••••••••••••••••••••••••••*/
  49. #define ON_BUTTON 1            
  50. #define OFF_BUTTON 2        
  51. #define USER_ITEM_SCROLL_BAR_COVER 4
  52. #define    THE_SCROLL_BAR 5
  53. #define    ABOUT_BUTTON 6
  54. #define ENTIRE_ABOUT_BOX 7
  55.  
  56.                                          /*••••••••••••••••••••••••••••••••••••••••••
  57.                                            •                                        •
  58.                                            •    Other constants                        •
  59.                                            •                                        •
  60.                                            ••••••••••••••••••••••••••••••••••••••••••*/
  61. #define ON true
  62. #define OFF false
  63.  
  64.  
  65.                                          /*••••••••••••••••••••••••••••••••••••••••••
  66.                                            •                                        •
  67.                                            •    Function Prototypes.                •
  68.                                            •                                        •
  69.                                            ••••••••••••••••••••••••••••••••••••••••••*/
  70.  
  71. void Handle_Scroll_Bar_Hit(Handle cdevStorage, DialogPtr CPDialog, short numItems);
  72. void Init_On_Off_Button_Manager(DialogPtr CPDialog, short numItems, Handle cdevStorage);
  73. void Turn_On(DialogPtr CPDialog, short numItems, Handle cdevStorage);
  74. void Turn_Off(DialogPtr CPDialog, short numItems, Handle cdevStorage);
  75. void Update_Sludge_Factor_Display(Handle cdevStorage);
  76. void Draw_About_Message();
  77. void Draw_My_Items(Handle cdevStorage, DialogPtr CPDialog, short numItems);
  78. void React_To_About_Button_Hit(Handle cdevStorage, DialogPtr CPDialog, short numItems);
  79. void Hide_The_Controls(DialogPtr CPDialog, short numItems);
  80. void Enable_And_Show_The_Controls(DialogPtr CPDialog, short numItems);
  81. void Close_About_Box(Handle cdevStorage, DialogPtr CPDialog, short numItems);
  82. void Draw_My_BackGround();
  83. void Fill_The_SLUDGE_BackGround_With_DeskTop_Pattern(RgnHandle back_region);
  84.  
  85.  
  86. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  87.   •                                                                           •
  88.   •   Identifier:     SLUDGECDEV                                                  •
  89.   •   -----------                                                             •
  90.   •                                                                           •
  91.   •       Description                                                         •
  92.   •       -----------                                                         •
  93.   •       This function is the main cdev function for the SLUDGE cdev.  For   •
  94.   •          more info on cdev routines and their parameters, see Inside Mac V.  •
  95.   •                                                                           •
  96.   •       History                                                             •
  97.   •       -------                                                             •
  98.   •                                                                           •
  99.   •       Author          Date            Description                         •
  100.   •       ------------------------------------------------------------------  •
  101.   •       Kevin McEntee   2/20/90         Original Implementation             •
  102.   •                                                                           •
  103.   •                                                                           •
  104.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  105. pascal Handle
  106. SLUDGECDEV(short message, short item, short numItems, short CPanelID,
  107.          EventRecord *theEvent, Handle cdevStorage, DialogPtr CPDialog)
  108. {                                    
  109.     
  110.         
  111.     
  112.     #pragma unused ( theEvent, CPanelID)                        /* unused formal parameters */
  113.  
  114.     if (message == macDev) return((Handle) 1);                
  115.     else if (cdevStorage != nil) {
  116.         switch (message) {
  117.                                          /*••••••••••••••••••••••••••••••••••••••••••
  118.                                            •                                        •
  119.                                            •    Initialize cdev                        •
  120.                                            •                                        •
  121.                                            ••••••••••••••••••••••••••••••••••••••••••*/
  122.             case initDev:                                    /* initialize cdev */
  123.                 SetUp_State_Storage(&cdevStorage);    
  124.                 
  125.                 if (State_Storage_Allocated(cdevStorage))
  126.                     {
  127.                     Clear_About_Box_State(cdevStorage);
  128.                     Init_On_Off_Button_Manager(CPDialog, numItems, cdevStorage);
  129.                     
  130.                     Draw_My_Items(cdevStorage, CPDialog, numItems);
  131.                     Draw_My_BackGround();
  132.                     Turn_Off(CPDialog, numItems, cdevStorage);
  133.                     
  134.                     if (Get_On_Off_Error_Condition(cdevStorage))
  135.                         cdevStorage = (Handle) Get_On_Off_Recommended_CDEV_Return_Value(cdevStorage);
  136.                     }
  137.  
  138.                 break;
  139.  
  140.                                          /*••••••••••••••••••••••••••••••••••••••••••
  141.                                            •                                        •
  142.                                            •    Process hitDev.                        •
  143.                                            •                                        •
  144.                                            ••••••••••••••••••••••••••••••••••••••••••*/
  145.             case hitDev:                                    
  146.                 switch (item - numItems) {
  147.                     case ON_BUTTON:
  148.                         if (!In_About_Box_State(cdevStorage))
  149.                             {
  150.                             Turn_On(CPDialog, numItems, cdevStorage);
  151.                             if (Get_On_Off_Error_Condition(cdevStorage))
  152.                                 cdevStorage = (Handle) Get_On_Off_Recommended_CDEV_Return_Value(cdevStorage);
  153.                             }
  154.                         else
  155.                             Close_About_Box(cdevStorage, CPDialog, numItems);
  156.                         break;
  157.                         
  158.                     case OFF_BUTTON:
  159.                         if (!In_About_Box_State(cdevStorage))
  160.                             {
  161.                             Turn_Off(CPDialog, numItems, cdevStorage);
  162.                             if (Get_On_Off_Error_Condition(cdevStorage))
  163.                                 cdevStorage = (Handle) Get_On_Off_Recommended_CDEV_Return_Value(cdevStorage);
  164.                             }
  165.                         else
  166.                             Close_About_Box(cdevStorage, CPDialog, numItems);
  167.                         break;
  168.                     case ENTIRE_ABOUT_BOX:
  169.                         if (In_About_Box_State(cdevStorage))
  170.                             Close_About_Box(cdevStorage, CPDialog, numItems);
  171.                         break;
  172.                     
  173.                     case ABOUT_BUTTON:
  174.                         React_To_About_Button_Hit(cdevStorage, CPDialog, numItems);
  175.                         break;
  176.                     
  177.                     case USER_ITEM_SCROLL_BAR_COVER:
  178.                         if (!In_About_Box_State(cdevStorage))
  179.                             Handle_Scroll_Bar_Hit( cdevStorage,  CPDialog,  numItems);
  180.                         else
  181.                             Close_About_Box(cdevStorage, CPDialog, numItems);
  182.                         break;
  183.     
  184.                         
  185.                         };
  186.                 break;
  187.             case closeDev:                                    /* clean up and dispose */
  188.                 break;
  189.             case nulDev:
  190.                 
  191.                 break;
  192.             case updateDev:                                  /* handle any Update drawing */
  193.                 Draw_My_Items(cdevStorage, CPDialog, numItems);    
  194.                 Draw_My_BackGround();                
  195.                 break;
  196.             case activDev:                                    /* activate any needed items */
  197.                 break;
  198.             case deactivDev:                                /* deactivate any needed items */
  199.                 break;
  200.                 
  201.             case keyEvtDev:                                    /* respond to keydown */
  202.                 break;
  203.                 
  204.             case macDev:
  205.             case undoDev:
  206.                 break;
  207.                 
  208.             case cutDev:
  209.             case copyDev:
  210.             case pasteDev:
  211.             case clearDev:
  212.                 break;
  213.         }
  214.  
  215.         return (cdevStorage);
  216.     }  /* cdevStorage != nil */
  217.     
  218.     /* 
  219.     **    if cdevStorage = NIL then ControlPanel 
  220.     **  will put up memory error
  221.     */
  222.     return (nil);
  223. }
  224.  
  225.  
  226. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  227.   •                                                                           •
  228.   •   Identifier:      Handle_Scroll_Bar_Hit                                   •
  229.   •   -----------                                                             •
  230.   •                                                                           •
  231.   •       Description                                                         •
  232.   •       -----------                                                         •
  233.   •       This routines handles the manipulations of the scroll bar that is   •
  234.   •          used to set the SLUDGE factor.  Since the control panel would only  •
  235.   •          call the SLUDGE cdev with a scroll bar event after a mouseUp, and   •
  236.   •          SLUDGE wanted control after a mouseDown, I implemented a user item  •
  237.   •          with the same rectangle as the scroll bar and wrote this code to    •
  238.   •          operate the scroll bar.                                              •
  239.   •                                                                           •
  240.   •       History                                                             •
  241.   •       -------                                                             •
  242.   •                                                                           •
  243.   •       Author          Date            Description                         •
  244.   •       ------------------------------------------------------------------  •
  245.   •       Kevin McEntee   2/20/90         Original Implementation             •
  246.   •                                                                           •
  247.   •                                                                           •
  248.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  249. void Handle_Scroll_Bar_Hit(Handle cdevStorage, DialogPtr CPDialog, short numItems)
  250. {
  251.     
  252.     short             itemType;
  253.     ControlHandle    itemHandle;
  254.     Rect            itemRect;
  255.     Point            mouseLoc;
  256.     short            scroll_bar_part_code;
  257.     long            i;
  258.         
  259.  
  260.     GetDItem(CPDialog, THE_SCROLL_BAR + numItems, &itemType, (Handle *) &itemHandle, &itemRect);
  261.     GetMouse(&mouseLoc);
  262.     scroll_bar_part_code = TestControl(itemHandle, mouseLoc);
  263.     
  264.     switch (scroll_bar_part_code) {
  265.         case inUpButton:
  266.             while (StillDown())
  267.                 {
  268.                 GetMouse(&mouseLoc);
  269.                 if ( TestControl(itemHandle, mouseLoc) == inUpButton )
  270.                     {
  271.                     HiliteControl(itemHandle, inUpButton);
  272.                     SetCtlValue(itemHandle, GetCtlValue(itemHandle) - 1);
  273.                     Increment_Sludge_Factor(cdevStorage);
  274.                     Update_Sludge_Factor_Display(cdevStorage);
  275.                     i = TickCount() + 4;
  276.                     while (TickCount() < i)
  277.                         ;
  278.                     }
  279.                 else
  280.                     HiliteControl(itemHandle, 0);
  281.                 }
  282.             HiliteControl(itemHandle, 0);
  283.             break;
  284.         case inDownButton:
  285.             while (StillDown())
  286.                 {
  287.                 GetMouse(&mouseLoc);
  288.                 if ( TestControl(itemHandle, mouseLoc) == inDownButton )
  289.                     {
  290.                     HiliteControl(itemHandle, inDownButton);
  291.                     SetCtlValue(itemHandle, GetCtlValue(itemHandle) + 1);
  292.                     Decrement_Sludge_Factor(cdevStorage);
  293.                     Update_Sludge_Factor_Display(cdevStorage);
  294.                     i = TickCount() + 4;
  295.                     while (TickCount() < i)
  296.                         ;
  297.                     }
  298.                 else
  299.                     HiliteControl(itemHandle, 0);
  300.                 }
  301.             HiliteControl(itemHandle, 0);
  302.             break;
  303.         case inThumb:
  304.             if (TrackControl(itemHandle, mouseLoc, nil) == inThumb)
  305.                 {
  306.                 Set_Sludge_Factor(cdevStorage, 999 - GetCtlValue(itemHandle));
  307.                 Update_Sludge_Factor_Display(cdevStorage);
  308.                 }
  309.             break;
  310.         case inPageUp:
  311.             while (StillDown())
  312.                 {
  313.                 GetMouse(&mouseLoc);
  314.                 if (TestControl(itemHandle, mouseLoc) == inPageUp )
  315.                     {
  316.                     SetCtlValue(itemHandle, GetCtlValue(itemHandle) - 20);
  317.                     Set_Sludge_Factor(cdevStorage, 999 - GetCtlValue(itemHandle));
  318.                     Update_Sludge_Factor_Display(cdevStorage);
  319.                     i = TickCount() + 4;
  320.                     while (TickCount() < i)
  321.                         ;
  322.                     }
  323.                 }
  324.         break;
  325.     case inPageDown:
  326.         while (StillDown())
  327.             {
  328.             GetMouse(&mouseLoc);
  329.             if (TestControl(itemHandle, mouseLoc) == inPageDown )
  330.                 {
  331.                 SetCtlValue(itemHandle, GetCtlValue(itemHandle) + 20);
  332.                 Set_Sludge_Factor(cdevStorage, 999 - GetCtlValue(itemHandle));
  333.                 Update_Sludge_Factor_Display(cdevStorage);
  334.                 i = TickCount() + 4;
  335.                 while (TickCount() < i)
  336.                     ;
  337.                 }
  338.             }
  339.         break;
  340.                 
  341.         };
  342.     
  343. }
  344.  
  345.  
  346. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  347.   •                                                                           •
  348.   •   Identifier:      Draw_My_Items                                              •
  349.   •   -----------                                                             •
  350.   •                                                                           •
  351.   •       Description                                                         •
  352.   •       -----------                                                         •
  353.   •       This function is called whenever the SLUDGE cdev gets an updateDev  •
  354.   •          message.                                                              •
  355.   •                                                                           •
  356.   •       History                                                             •
  357.   •       -------                                                             •
  358.   •                                                                           •
  359.   •       Author          Date            Description                         •
  360.   •       ------------------------------------------------------------------  •
  361.   •       Kevin McEntee   2/20/90         Original Implementation             •
  362.   •                                                                           •
  363.   •                                                                           •
  364.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  365. void Draw_My_Items(Handle cdevStorage, DialogPtr CPDialog, short numItems)
  366. {
  367.     ControlHandle    scroll_bar_handle;
  368.     short             itemType;
  369.     Rect            itemRect;
  370.     
  371.     
  372.     
  373.     if (In_About_Box_State(cdevStorage))
  374.         {
  375.         Hide_The_Controls(CPDialog, numItems);
  376.         Draw_About_Message();
  377.         }
  378.     else
  379.         {
  380.         Update_Sludge_Factor_Display(cdevStorage);
  381.         
  382.         /* draw the scroll bar with the correct thumb position */
  383.         GetDItem(CPDialog, THE_SCROLL_BAR + numItems, &itemType, (Handle *) &scroll_bar_handle, &itemRect);
  384.         SetCtlValue(scroll_bar_handle, 999 - Get_Sludge_Factor(cdevStorage));
  385.         
  386.         /* draw "SLUDGE Factor:";  I had to draw this string here (instead of making it a DITL item, because of
  387.             SLUDGE's unique about box. */
  388.         MoveTo(105,155);
  389.         DrawString((Str255) "\pSLUDGE Factor:");
  390.         }
  391. }
  392.  
  393.  
  394.  
  395. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  396.   •                                                                           •
  397.   •   Identifier:        Update_Sludge_Factor_Display                          •
  398.   •   -----------                                                             •
  399.   •                                                                           •
  400.   •       Description                                                         •
  401.   •       -----------                                                         •
  402.   •       This function draws the numerical SLUDGE factor value.              •
  403.   •                                                                           •
  404.   •       History                                                             •
  405.   •       -------                                                             •
  406.   •                                                                           •
  407.   •       Author          Date            Description                         •
  408.   •       ------------------------------------------------------------------  •
  409.   •       Kevin McEntee   2/20/90         Original Implementation             •
  410.   •                                                                           •
  411.   •                                                                           •
  412.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  413. void Update_Sludge_Factor_Display(Handle cdevStorage)
  414. {
  415.     long local_sludge;
  416.     Rect  r;
  417.     char c1,c2,c3;
  418.     
  419.     /* Get the current value */
  420.     
  421.     HLock(cdevStorage);
  422.     local_sludge = ((State_Storage_Pointer) *cdevStorage)->Sludge_Factor;
  423.     HUnlock(cdevStorage);
  424.     
  425.     
  426.     /* calulate character representation of the value */
  427.     
  428.     c1 = (char) ((local_sludge / 100) % 10) + 48;
  429.     c2 = (char) ((local_sludge / 10) % 10) + 48;
  430.     c3 = (char) (local_sludge % 10) + 48;
  431.  
  432.  
  433.     /* Draw the value */
  434.     
  435.     r.left = 180;
  436.     r.right = 210;
  437.     r.top = 140;
  438.     r.bottom = 180;
  439.     
  440.     EraseRect(&r);
  441.     MoveTo(185,155);
  442.     DrawChar(c1);
  443.     DrawChar(c2);
  444.     DrawChar(c3);
  445. }
  446.     
  447.     
  448.     
  449.  
  450. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  451.   •                                                                           •
  452.   •   Identifier:        Draw_About_Message                                    •
  453.   •   -----------                                                             •
  454.   •                                                                           •
  455.   •       Description                                                         •
  456.   •       -----------                                                         •
  457.   •       This function draws the strings that make up the messages of the    •
  458.   •          SLUDGE about box.                                                      •
  459.   •                                                                           •
  460.   •       History                                                             •
  461.   •       -------                                                             •
  462.   •                                                                           •
  463.   •       Author          Date            Description                         •
  464.   •       ------------------------------------------------------------------  •
  465.   •       Kevin McEntee   2/20/90         Original Implementation             •
  466.   •                                                                           •
  467.   •                                                                           •
  468.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  469. void Draw_About_Message()
  470. {
  471.     StringHandle  current_string;
  472.  
  473.     
  474.     
  475.     current_string = GetString(1);
  476.     MoveTo(105, 90);
  477.     DrawString((Str255) *current_string);
  478.     
  479.     current_string = GetString(2);
  480.     MoveTo(105, 102);
  481.     DrawString((Str255) *current_string);
  482.     
  483.     current_string = GetString(3);
  484.     MoveTo(105, 114);
  485.     DrawString((Str255) *current_string);
  486.     
  487.     current_string = GetString(4);
  488.     MoveTo(105, 126);
  489.     DrawString((Str255) *current_string);
  490.     
  491.     current_string = GetString(5);
  492.     MoveTo(105, 138);
  493.     DrawString((Str255) *current_string);
  494.     
  495.     current_string = GetString(6);
  496.     MoveTo(105, 160);
  497.     DrawString((Str255) *current_string);
  498.     
  499.     current_string = GetString(7);
  500.     MoveTo(105, 172);
  501.     DrawString((Str255) *current_string);
  502.     
  503.     current_string = GetString(8);
  504.     MoveTo(105, 184);
  505.     DrawString((Str255) *current_string);
  506.     
  507.     current_string = GetString(9);
  508.     MoveTo(105, 206);
  509.     DrawString((Str255) *current_string);
  510.     
  511.     current_string = GetString(10);
  512.     MoveTo(105, 228);
  513.     DrawString((Str255) *current_string);
  514.     
  515.     
  516.     
  517. }    
  518.  
  519.  
  520.  
  521. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  522.   •                                                                           •
  523.   •   Identifier:         Close_About_Box                                      •
  524.   •   -----------                                                             •
  525.   •                                                                           •
  526.   •       Description                                                         •
  527.   •       -----------                                                         •
  528.   •       This function erases the message of the about box and re-draws the  •
  529.   •          SLUDGE controls.                                                      •
  530.   •                                                                           •
  531.   •       History                                                             •
  532.   •       -------                                                             •
  533.   •                                                                           •
  534.   •       Author          Date            Description                         •
  535.   •       ------------------------------------------------------------------  •
  536.   •       Kevin McEntee   2/20/90         Original Implementation             •
  537.   •                                                                           •
  538.   •                                                                           •
  539.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  540. void Close_About_Box(Handle cdevStorage, DialogPtr CPDialog, short numItems)
  541. {
  542.     Rect            about_box_rect;
  543.     
  544.     about_box_rect.left = 96;
  545.     about_box_rect.right = 308;
  546.     about_box_rect.top = 74;
  547.     about_box_rect.bottom = 239;
  548.  
  549.     Clear_About_Box_State(cdevStorage);
  550.     EraseRect(&about_box_rect);
  551.     Enable_And_Show_The_Controls(CPDialog, numItems);
  552.     DrawControls(CPDialog);
  553.     Draw_My_Items(cdevStorage, CPDialog, numItems);
  554. }
  555.  
  556.  
  557. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  558.   •                                                                           •
  559.   •   Identifier:      React_To_About_Button_Hit                                  •
  560.   •   -----------                                                             •
  561.   •                                                                           •
  562.   •       Description                                                         •
  563.   •       -----------                                                         •
  564.   •       If the about box is currently displayed, this function calls        •
  565.   •          Close_About_Box, otherwise it scrolls away the SLUDGE controls      •
  566.   •          and draws the about box.                                              •
  567.   •                                                                           •
  568.   •       History                                                             •
  569.   •       -------                                                             •
  570.   •                                                                           •
  571.   •       Author          Date            Description                         •
  572.   •       ------------------------------------------------------------------  •
  573.   •       Kevin McEntee   2/20/90         Original Implementation             •
  574.   •                                                                           •
  575.   •                                                                           •
  576.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  577. void React_To_About_Button_Hit(Handle cdevStorage, DialogPtr CPDialog, short numItems)
  578. {
  579.     Rect            scrolling_rect;
  580.     RgnHandle        My_Scrolling_Update_Region;
  581.     RgnHandle        Current_Clip_Region;
  582.     long             i,j;
  583.     
  584.     
  585.     if (In_About_Box_State(cdevStorage))
  586.         Close_About_Box(cdevStorage, CPDialog, numItems);
  587.     else
  588.         {
  589.         scrolling_rect.left = 96;
  590.         scrolling_rect.right = 308;
  591.         scrolling_rect.top = 74;
  592.         scrolling_rect.bottom = 239;
  593.  
  594.         Set_About_Box_State(cdevStorage);
  595.                 
  596.         
  597.         
  598.         My_Scrolling_Update_Region = NewRgn();
  599.         Current_Clip_Region = NewRgn();
  600.         
  601.         for (j=0; j < 57; j++)
  602.             {
  603.             ScrollRect(&scrolling_rect, 0, 3, My_Scrolling_Update_Region);
  604.             
  605.             GetClip(Current_Clip_Region);
  606.             SetClip(My_Scrolling_Update_Region);
  607.             Draw_About_Message();
  608.             
  609.             SetClip(Current_Clip_Region);
  610.             
  611.             scrolling_rect.top = scrolling_rect.top + 3;
  612.             
  613.             i = TickCount() + 1;
  614.             while (TickCount() < i)
  615.                 ;
  616.             }
  617.             
  618.         DisposeRgn(My_Scrolling_Update_Region);
  619.         DisposeRgn(Current_Clip_Region);
  620.         
  621.         }
  622. }
  623.  
  624.  
  625.  
  626.  
  627. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  628.   •                                                                           •
  629.   •   Identifier:      Hide_The_Controls                                       •
  630.   •   -----------                                                             •
  631.   •                                                                           •
  632.   •       Description                                                         •
  633.   •       -----------                                                         •
  634.   •       This function marks the controls of the SLUDGE cdev as hidden so    •
  635.   •          they are not displayed by the Control Panel during an update event. •
  636.   •          You don't want them displayed when the SLUDGE cdev is in the about  •
  637.   •          box state.                                                          •  
  638.   •                                                                           •
  639.   •       History                                                             •
  640.   •       -------                                                             •
  641.   •                                                                           •
  642.   •       Author          Date            Description                         •
  643.   •       ------------------------------------------------------------------  •
  644.   •       Kevin McEntee   2/20/90         Original Implementation             •
  645.   •                                                                           •
  646.   •                                                                           •
  647.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  648. void Hide_The_Controls(DialogPtr CPDialog, short numItems)
  649. {
  650.     short             itemType;
  651.     ControlHandle    itemHandle;
  652.     Rect            itemRect;
  653.     
  654.     GetDItem(CPDialog, THE_SCROLL_BAR + numItems, &itemType, (Handle *) &itemHandle, &itemRect);
  655.     HideControl(itemHandle);
  656.     
  657.     GetDItem(CPDialog, ON_BUTTON + numItems, &itemType, (Handle *) &itemHandle, &itemRect);
  658.     HideControl(itemHandle);
  659.     
  660.     GetDItem(CPDialog, OFF_BUTTON + numItems, &itemType, (Handle *) &itemHandle, &itemRect);
  661.     HideControl(itemHandle);
  662.  
  663. }
  664.  
  665. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  666.   •                                                                           •
  667.   •   Identifier:      Enable_And_Show_The_Controls                              •
  668.   •   -----------                                                             •
  669.   •                                                                           •
  670.   •       Description                                                         •
  671.   •       -----------                                                         •
  672.   •       This function marks the controls of the SLUDGE cdev as visible so   •
  673.   •          they are displayed by the Control Panel during an update event.     •
  674.   •          You don't want them displayed when the SLUDGE cdev is not in the       •
  675.   •          about box state.                                                      •  
  676.   •                                                                           •
  677.   •       History                                                             •
  678.   •       -------                                                             •
  679.   •                                                                           •
  680.   •       Author          Date            Description                         •
  681.   •       ------------------------------------------------------------------  •
  682.   •       Kevin McEntee   2/20/90         Original Implementation             •
  683.   •                                                                           •
  684.   •                                                                           •
  685.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  686. void Enable_And_Show_The_Controls(DialogPtr CPDialog, short numItems)
  687. {
  688.     short             itemType;
  689.     ControlHandle    itemHandle;
  690.     Rect            itemRect;
  691.  
  692.     GetDItem(CPDialog, THE_SCROLL_BAR + numItems, &itemType, (Handle *) &itemHandle, &itemRect);
  693.     HiliteControl(itemHandle, 0); 
  694.     ShowControl(itemHandle);
  695.     
  696.     GetDItem(CPDialog, ON_BUTTON + numItems, &itemType, (Handle *) &itemHandle, &itemRect);
  697.     HiliteControl(itemHandle, 0); 
  698.     ShowControl(itemHandle);
  699.     
  700.     GetDItem(CPDialog, OFF_BUTTON + numItems, &itemType, (Handle *) &itemHandle, &itemRect);
  701.     HiliteControl(itemHandle, 0);
  702.     ShowControl(itemHandle);
  703.  
  704. }
  705.  
  706.  
  707.  
  708. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  709.   •                                                                           •
  710.   •   Identifier:        Draw_My_BackGround                                    •
  711.   •   -----------                                                             •
  712.   •                                                                           •
  713.   •       Description                                                         •
  714.   •       -----------                                                         •
  715.   •       This function draws the background of the SLUDGE cdev.              •
  716.   •                                                                           •
  717.   •       History                                                             •
  718.   •       -------                                                             •
  719.   •                                                                           •
  720.   •       Author          Date            Description                         •
  721.   •       ------------------------------------------------------------------  •
  722.   •       Kevin McEntee   2/20/90         Original Implementation             •
  723.   •                                                                           •
  724.   •                                                                           •
  725.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  726. void Draw_My_BackGround()
  727. {
  728.     Rect             nrctRect, shadow_rect;
  729.     RgnHandle        temp1_region, temp2_region;
  730.     RGBColor        current_color, op_color;
  731.     
  732.     current_color.red   = 0;
  733.     current_color.green = 0;
  734.     current_color.blue  = 0;
  735.     RGBForeColor(¤t_color);
  736.     PenNormal();
  737.  
  738.     temp1_region = NewRgn();
  739.     temp2_region = NewRgn();
  740.     
  741.     
  742.                                          /*••••••••••••••••••••••••••••••••••••••••••
  743.                                            •                                        •
  744.                                            •    Frame the rects containing the         •
  745.                                            •    SLUDGE controls.  (Theses rects are •
  746.                                            •    not 'nrct's because I wanted to     •
  747.                                            •    draw my fancy background.)          •
  748.                                            •    AND calculate the region that is    •
  749.                                            •    everything but these rects.  I will •
  750.                                            •    fill this region with the background•
  751.                                            •    pattern.                            •
  752.                                            •                                        •
  753.                                            ••••••••••••••••••••••••••••••••••••••••••*/
  754.     SetRectRgn(temp1_region,89,1, 321, 254); /* all of the cpanel, used by Sludge */
  755.     
  756.     
  757.     nrctRect.left   = 94;                /* The big rect with main controls */
  758.     nrctRect.right  = 310;
  759.     nrctRect.top    = 73;
  760.     nrctRect.bottom = 241;
  761.     
  762.     FrameRect(&nrctRect);
  763.     
  764.     RectRgn(temp2_region, &nrctRect);
  765.     DiffRgn(temp1_region, temp2_region, temp1_region); 
  766.     
  767.         
  768.     nrctRect.left   = 94;                /* The rect with SLUDGE title */
  769.     nrctRect.right  = 235;
  770.     nrctRect.top    = 3;
  771.     nrctRect.bottom = 67;
  772.     
  773.     FrameRect(&nrctRect);
  774.     
  775.     RectRgn(temp2_region, &nrctRect);
  776.     DiffRgn(temp1_region, temp2_region, temp1_region); 
  777.  
  778.     
  779.     nrctRect.left   = 241;                /* The rect with the 'About' button */
  780.     nrctRect.right  = 310;
  781.     nrctRect.top    = 3;
  782.     nrctRect.bottom = 67;
  783.     
  784.     FrameRect(&nrctRect);
  785.     
  786.     RectRgn(temp2_region, &nrctRect);
  787.     DiffRgn(temp1_region, temp2_region, temp1_region); 
  788.  
  789.  
  790.     /* Draw interesting stuff here */
  791.     
  792.     Fill_The_SLUDGE_BackGround_With_DeskTop_Pattern(temp1_region);
  793.  
  794.                                          /*••••••••••••••••••••••••••••••••••••••••••
  795.                                            •                                        •
  796.                                            •    Shadow the rectangles to give offset•
  797.                                            •    look.                                •
  798.                                            •                                        •
  799.                                            ••••••••••••••••••••••••••••••••••••••••••*/
  800.     current_color.red   = 0x2000;;
  801.     current_color.green = 0x2000;
  802.     current_color.blue  = 0x2000;
  803.     RGBForeColor(¤t_color);
  804.     
  805.     op_color.red    = 0x8000;
  806.     op_color.green  = 0x8000;
  807.     op_color.blue   = 0x8000;
  808.     OpColor(&op_color);
  809.     
  810.     PenSize(1,1);
  811.     PenMode(blend);
  812.     
  813.     
  814.     /* bottom of rect with main controls */
  815.     shadow_rect.left    = 96;
  816.     shadow_rect.right   = 310;
  817.     shadow_rect.top     = 241;
  818.     shadow_rect.bottom  = 244;
  819.     PaintRect(&shadow_rect);
  820.  
  821.     /* side of rect with main controls */
  822.     shadow_rect.left    = 310;
  823.     shadow_rect.right   = 313;
  824.     shadow_rect.top     = 75;
  825.     shadow_rect.bottom  = 244;
  826.     PaintRect(&shadow_rect);
  827.     
  828.     
  829.     /* bottom of rect with SLUDGE title */
  830.     shadow_rect.left    = 96;
  831.     shadow_rect.right   = 235;
  832.     shadow_rect.top     = 67;
  833.     shadow_rect.bottom  = 70;
  834.     PaintRect(&shadow_rect);
  835.  
  836.     /* side of rect with SLUDGE title */
  837.     shadow_rect.left    = 235;
  838.     shadow_rect.right   = 238;
  839.     shadow_rect.top     = 5;
  840.     shadow_rect.bottom  = 70;
  841.     PaintRect(&shadow_rect);
  842.     
  843.     
  844.     /* bottom of rect with about button */
  845.     shadow_rect.left    = 243;
  846.     shadow_rect.right   = 310;
  847.     shadow_rect.top     = 67;
  848.     shadow_rect.bottom  = 70;
  849.     PaintRect(&shadow_rect);
  850.  
  851.     /* side of rect with about button  */
  852.     shadow_rect.left    = 310;
  853.     shadow_rect.right   = 313;
  854.     shadow_rect.top     = 5;
  855.     shadow_rect.bottom  = 70;
  856.     PaintRect(&shadow_rect);
  857.  
  858.     
  859.  
  860.     current_color.red   = 0;
  861.     current_color.green = 0;
  862.     current_color.blue  = 0;
  863.     RGBForeColor(¤t_color);
  864.     PenNormal();
  865.         
  866.  
  867.     
  868. }
  869.  
  870.  
  871. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  872.   •                                                                           •
  873.   •   Identifier:       Fill_The_SLUDGE_BackGround_With_DeskTop_Pattern        •
  874.   •   -----------                                                             •
  875.   •                                                                           •
  876.   •       Description                                                         •
  877.   •       -----------                                                         •
  878.   •       This function fills the background of the SLUDGE cdev with the      •
  879.   •          current desktop pattern.                                              •
  880.   •                                                                           •
  881.   •       History                                                             •
  882.   •       -------                                                             •
  883.   •                                                                           •
  884.   •       Author          Date            Description                         •
  885.   •       ------------------------------------------------------------------  •
  886.   •       Kevin McEntee   2/20/90         Original Implementation             •
  887.   •                                                                           •
  888.   •                                                                           •
  889.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  890. void Fill_The_SLUDGE_BackGround_With_DeskTop_Pattern(RgnHandle back_region)
  891. {
  892.     
  893.     Ptr    SPMisc2;            /* Inside Mac xref */
  894.         
  895.     SPMisc2 = (Ptr) 0x20B;
  896.     
  897.     /* If bit 7 is set for this byte then, a color PixPattern is the background */
  898.     /* pattern, otherwise the b&w pattern at $A3C is the background pattern */
  899.     
  900.     if (*SPMisc2 < 0)
  901.         FillCRgn(back_region, GetPixPat(16));    /* Use 'ppat'=16 resource in system file */
  902.     else
  903.         FillRgn(back_region, (Pattern) 0xA3C);    /* Use the 'pattern' at location $A3C */
  904. }
  905.  
  906.  
  907. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  908.   •                                                                           •
  909.   •   Function Name:      Update_On_Off_Button_Display                        •
  910.   •   --------------                                                          •
  911.   •                                                                           •
  912.   •       Description                                                         •
  913.   •       -----------                                                         •
  914.   •       This command sets the visible condition of the On/Off buttons based •
  915.   •          on the current value from the state storage manager.                  •
  916.   •                                                                           •
  917.   •       History                                                             •
  918.   •       -------                                                             •
  919.   •                                                                           •
  920.   •       Author          Date            Description                         •
  921.   •       ------------------------------------------------------------------  •
  922.   •       Kevin McEntee   7/20/89         Original Implementation             •
  923.   •                                                                           •
  924.   •                                                                           •
  925.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  926. void Update_On_Off_Button_Display(DialogPtr CPDialog, short numItems, Handle cdevStorage)
  927. {
  928.     short        itemType;
  929.     Rect        itemRect;
  930.     Handle        itemHand;
  931.  
  932.     int  On_Off_Value = Get_ONFF_Value(cdevStorage);
  933.         
  934.     if (!Get_On_Off_Error_Condition(cdevStorage))
  935.         {
  936.         if (On_Off_Value == ON)
  937.             {
  938.             GetDItem(CPDialog, numItems + ON_BUTTON, &itemType, &itemHand, &itemRect);
  939.             SetCtlValue( (ControlHandle) itemHand, 1);
  940.                 
  941.             GetDItem(CPDialog, numItems + OFF_BUTTON, &itemType, &itemHand, &itemRect);
  942.             SetCtlValue( (ControlHandle) itemHand, 0);
  943.                 
  944.             }
  945.         else
  946.             {
  947.             GetDItem(CPDialog, numItems + ON_BUTTON, &itemType, &itemHand, &itemRect);
  948.             SetCtlValue( (ControlHandle) itemHand, 0);
  949.         
  950.             GetDItem(CPDialog, numItems + OFF_BUTTON, &itemType, &itemHand, &itemRect);
  951.             SetCtlValue( (ControlHandle) itemHand, 1);
  952.             
  953.             }
  954.         }
  955. }
  956.  
  957.  
  958.  
  959. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  960.   •                                                                           •
  961.   •   Function Name:      Init_On_Off_Button_Manager                          •
  962.   •   --------------                                                          •
  963.   •                                                                           •
  964.   •       Description                                                         •
  965.   •       -----------                                                         •
  966.   •       This command performs any initialization actions for the On/Off       •
  967.   •          buttons, including calling the button update command and setting      •
  968.   •          the On/Off error condition to false.                                  •
  969.   •                                                                              •                                                                           •
  970.   •       History                                                             •
  971.   •       -------                                                             •
  972.   •                                                                           •
  973.   •       Author          Date            Description                         •
  974.   •       ------------------------------------------------------------------  •
  975.   •       Kevin McEntee   7/20/89         Original Implementation             •
  976.   •                                                                           •
  977.   •                                                                           •
  978.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  979. void Init_On_Off_Button_Manager(DialogPtr CPDialog, short numItems, Handle cdevStorage)
  980. {
  981.     Set_On_Off_Error_Condition(cdevStorage, false);
  982.     Update_On_Off_Button_Display(CPDialog,numItems,cdevStorage);
  983. }
  984.  
  985.  
  986.  
  987. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  988.   •                                                                           •
  989.   •   Function Name:     Turn_On                                              •
  990.   •   --------------                                                          •
  991.   •                                                                           •
  992.   •       Description                                                         •
  993.   •       -----------                                                         •
  994.   •       This command is called when the SLUDGE CDEV receives                   •
  995.   •       a hitDev message for the On button.                                 •
  996.   •                                                                              •
  997.   •          It starts the SLUDGING.                                              •
  998.   •                                                                           •
  999.   •       History                                                             •
  1000.   •       -------                                                             •
  1001.   •                                                                           •
  1002.   •       Author          Date            Description                         •
  1003.   •       ------------------------------------------------------------------  •
  1004.   •       Kevin McEntee   7/20/89         Original Implementation             •
  1005.   •                                                                           •
  1006.   •                                                                           •
  1007.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  1008. void Turn_On(DialogPtr CPDialog, short numItems, Handle cdevStorage) 
  1009. {
  1010.     int  On_Off_Value = Get_ONFF_Value(cdevStorage);
  1011.  
  1012.     if (!Get_On_Off_Error_Condition(cdevStorage))
  1013.         {
  1014.         if (On_Off_Value == OFF)
  1015.             {
  1016.             Set_ONFF_Value(cdevStorage, ON);
  1017.             if (!Get_On_Off_Error_Condition(cdevStorage))
  1018.                 {
  1019.                 Install(cdevStorage, Get_Sludge_Factor(cdevStorage));
  1020.                 Update_On_Off_Button_Display(CPDialog,numItems,cdevStorage);
  1021.                 }
  1022.             }
  1023.         }
  1024. }
  1025.  
  1026.  
  1027.  
  1028.  
  1029. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  1030.   •                                                                           •
  1031.   •   Function Name:     Turn_Off                                             •
  1032.   •   --------------                                                          •
  1033.   •                                                                           •
  1034.   •       Description                                                         •
  1035.   •       -----------                                                         •
  1036.   •       This command is called when the SLUDGE CDEV receives                   •
  1037.   •       a hitDev message for the Off button.                                •
  1038.   •                                                                              •
  1039.   •          It stops the SLUDGING.                                              •
  1040.   •                                                                           •
  1041.   •       History                                                             •
  1042.   •       -------                                                             •
  1043.   •                                                                           •
  1044.   •       Author          Date            Description                         •
  1045.   •       ------------------------------------------------------------------  •
  1046.   •       Kevin McEntee   7/20/89         Original Implementation             •
  1047.   •                                                                           •
  1048.   •                                                                           •
  1049.   •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  1050. void Turn_Off(DialogPtr CPDialog, short numItems, Handle cdevStorage) 
  1051. {    
  1052.     int  On_Off_Value = Get_ONFF_Value(cdevStorage);
  1053.  
  1054.     if (!Get_On_Off_Error_Condition(cdevStorage))
  1055.         {
  1056.         if (On_Off_Value == ON)
  1057.             {
  1058.             Set_ONFF_Value(cdevStorage, OFF);
  1059.             if (!Get_On_Off_Error_Condition(cdevStorage))
  1060.                 {
  1061.                 remove(cdevStorage);
  1062.                 Update_On_Off_Button_Display(CPDialog,numItems,cdevStorage);
  1063.                 }
  1064.             }
  1065.         }
  1066. }
  1067.